package tst

import org.codehaus.groovy.control.CompilerConfiguration

class MainTest {

	static public void main1(String[] args) {


		File sourceFile = new File("C:/WD/devworkspace/rulerepo/xsxdjc/script/斐波那契.groovy")
		
		GroovyClassLoader classLoader = 
		new GroovyClassLoader(Thread.currentThread().getContextClassLoader());
		
		//File sourceFile = new File("D:\\TestGroovy.groovy");
		Class testGroovyClass = classLoader.parseClass(new GroovyCodeSource(sourceFile));
		
		println testGroovyClass.getName();
		
		def ret = testGroovyClass.invokeMethod("applyRule", new Object())
println ret

	}
	
	static public void main2(String[] args) {
		Binding binding = new Binding(new HashMap())

		Properties myProperties = new Properties(System.getProperties());
		def myConfiguration = new CompilerConfiguration(myProperties);
		myConfiguration.setClasspath("C:/WD/devworkspace/rulerepo/")
		
		GroovyShell shell = new GroovyShell(binding,myConfiguration)


		shell.evaluate("result = with(xsxdjc.script.斐波那契.applyRule)")

		println binding.variables
	}
	
	static public void main(String[] args) {
		Binding binding = new Binding(new HashMap())
		binding.setProperty("x", 4)
		
		binding.setProperty("y", 5)
		
		Properties myProperties = new Properties(System.getProperties());
		def myConfiguration = new CompilerConfiguration(myProperties);
		myConfiguration.setClasspath("C:/WD/devworkspace/rulerepo/")
		myConfiguration.setSourceEncoding("UTF-8")
		
		GroovyShell shell = new GroovyShell(binding,myConfiguration)


		shell.evaluate("import static xsxdjc.script.Functions.add\nresult = add(3,4)")

		println binding.variables
		
		shell.evaluate("import static xsxdjc.script.Functions.add\nresult = add(x,y)")
		
				println binding.variables
	}
}
